<template>
  <div>
    控制台展示
  </div>
</template>

<script>
// import * as echarts from 'echarts'
import { get, put } from '@/api/request'
import { mapGetters } from 'vuex'
export default {
  name: 'Dashboard',
  components: { },
  data() {
    return {
      is_requestData_1: false,
      is_requestData_2: false,
      is_requestData_3: false,
      is_requestData_4: false,
      is_requestData_5: false,
      current_indicator_array: [],
      current_indicator_value: [],
      current_setting_array: [],
      current_setting_value: [],
      show_checkUpdate: false,
      adminMenus: [],
      evaluationData: {},
      new_evaluationData: {},
      diskInfo: {}
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ]),
    admin_dashboard() {
      this.$set(this, 'is_requestData_2', true)
      return this.$project_config.project_config?.admin_dashboard?.extension_menu || []
    }
  },
  created() {
    this.upData()
  },
  mounted() {
  },
  destroyed() { // 销毁实例解决图标未初始化完成快速切换出现错误
    // if (document.getElementById('evaluation_data')) echarts.init(document.getElementById('evaluation_data')).dispose()
    // if (document.getElementById('new_evaluation_data')) echarts.init(document.getElementById('new_evaluation_data')).dispose()
  },
  methods: {
    toRescue(url) {
      window.open(url, '_blank')
    },
    upData() {
      this.requestData()
    },
    async onFinish() {
      put('course/evaluation/setting/sync', { current_setting: this.current_setting_value, current_indicator: this.current_indicator_value }).then((response) => {
        if (response.code === 0) {
          this.show_checkUpdate = false
        }
      })
    },
    async requestData() {
      // await get(`course/evaluation/setting/check`).then(response => {
      //   if (response.code === 0) {
      //     this.checkUpdate = response.data
      //     this.current_indicator_array = Object.keys(response.data.current_indicator).map(item => {
      //       return {
      //         data: response.data.current_indicator[item],
      //         value: item
      //       }
      //     })
      //     this.current_setting_array = Object.keys(response.data.current_setting).map(item => {
      //       return {
      //         data: response.data.current_setting[item],
      //         value: item
      //       }
      //     })
      //     this.show_checkUpdate = !response.data.pass
      //   }
      // })
      await get(`dashboard/basic/data`).then(response => {
        if (response.code === 0) {
          const dataList = []
          Object.keys(response.data).map(item => {
            if (response.data[item].branchs) {
              response.data[item].branchs.forEach(el => {
                dataList.push(Object.assign(el, { icon: require('@/assets/icon/' + item + '.png') }))
              })
            } else {
              dataList.push(Object.assign(response.data[item], { icon: require('@/assets/icon/' + item + '.png') }))
            }
          })
          this.adminMenus = dataList
          this.$set(this, 'is_requestData_1', true)
        }
      })
      await get(`dashboard/course/evaluation/data`).then(response => {
        console.log('response.data', response.data)
        // if (response.code === 0) {
        //   this.evaluationData = response.data
        //   this.setEcharts(response.data.count, response.data.datetime, 'evaluation_data')
        // }
        // this.$set(this, 'is_requestData_3', true)
      })
      // await get(`dashboard/new/course/evaluation/data`).then(response => {
      //   if (response.code === 0) {
      //     this.new_evaluationData = response.data
      //     this.setEcharts(response.data.count, response.data.datetime, 'new_evaluation_data')
      //   }
      //   this.$set(this, 'is_requestData_4', true)
      // })
      await get(`dashboard/system/info`).then(response => {
        if (response.code === 0) {
          this.diskInfo = response.data.disk
        }
        this.$set(this, 'is_requestData_5', true)
      })
    },
    // 设置数据统计图【教秘、管理端】
    async setEcharts(count, datetime, type) {
      // if (!echarts) return
      // var myChart = echarts.init(document.getElementById(type))
      // const option = {
      //   title: {
      //     // text: '课程评价参评数据'
      //   },
      //   tooltip: {
      //     show: true,
      //     trigger: 'axis'
      //   },
      //   legend: {
      //     // data: ['销量']
      //   },
      //   xAxis: {
      //     data: datetime
      //   },
      //   yAxis: {},
      //   series: count
      // }
      // myChart.setOption(option)
    }
  }
}
</script>
<style lang="scss" scoped>
  @import '@/styles/sun-style.scss';
</style>
<style lang="scss">
.login-container {
		background-position: center;
		background-size: cover;
    display: flex;
    flex-direction: row;
    align-items:center;
    min-height: 100%;
    width: 100%;
    overflow: hidden;
}
</style>
